//
//  CEPointInsVC.m
//  digitalCurrency
//
//  Created by 默认账户 on 2019/4/3.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "CEPointInsVC.h"
#import "CEPintHeaderSuperView.h"
#import "CEPointInsCell.h"
#import "CEPointListController.h"
#import "CEPointInstructionModel.h"
#import "MineNetManager.h"
#import "CTQGCell.h"
@interface CEPointInsVC()

@property (nonatomic, strong) LYEmptyView *emptyView;
@property (nonatomic, strong) NSArray *listArr;

@end

@implementation CEPointInsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewTitle.text = LocalizationKey(@"理财收益");
    self.listArr = [[NSArray alloc]init];
    
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[CTQGCell class] forCellReuseIdentifier:@"qgcell"];
    self.tableView.separatorColor  = [UIColor clearColor];
    [self headRefreshWithScrollerView:self.tableView];
    
    [self getPointInstructionList];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    self.tableView.frame = self.view.bounds;
}

- (LYEmptyView *)emptyView {
    if (!_emptyView) {
        _emptyView = [LYEmptyView emptyViewWithImageStr:@"emptyData" titleStr:[[ChangeLanguage bundle] localizedStringForKey:@"NoData" value:nil table:@"English"]];
        _emptyView.titleLabTextColor = tThreeColor;
        _emptyView.titleLabFont = [UIFont systemFontOfSize:19];
        _emptyView.contentViewY = SCREEN_HEIGHT/2.0-100;
    }
    return _emptyView;
}

- (void)getPointInstructionList {
    [MineNetManager getCommunityInfo:@{@"pageNum":@"1",@"pageSize":@"50"} CompleteHandle:^(id resPonseObj, int code) {
        if (code) {
            NSInteger codeInt = [resPonseObj[@"code"] integerValue];
            if (codeInt == 0) {
                self.listArr = [[NSArray alloc]init];
                self.listArr = resPonseObj[@"data"][@"list"];
            }
            else {
                [self.view makeToast:resPonseObj[MESSAGE] duration:1.5 position:CSToastPositionCenter];
            }
            self.tableView.ly_emptyView = self.emptyView;
            [self.tableView reloadData];
        }
        else {
            [self.view makeToast:LocalizationKey(@"noNetworkStatus") duration:1.5 position:CSToastPositionCenter];
        }
    }];
}

//MARK:--下拉刷新
- (void)refreshHeaderAction {
    [self getPointInstructionList];
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellContentViewWidth:(CGFloat)width tableView:(UITableView *)tableView{
    return 49;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
     CTQGCell *cell = [CTQGCell createTableView:tableView];
       
       NSDictionary *dic = self.listArr[indexPath.row];
       cell.createTime.text = [NSString stringWithFormat:@"%@",dic[@"date"]];
       cell.coinNumber.text = [NSString stringWithFormat:@"%@ %@",[NSString stringWithFormat:@"%@", [ToolUtil judgeStringForDecimalPlaces:[dic[@"value"] stringValue] point:4]],dic[@"tocoinName"]];
       cell.coinName.text = [NSString stringWithFormat:@"%@",dic[@"coinName"]];

       cell.bgView.frame = CGRectMake(0, 0, kWindowW, 62);
       cell.bgView.layer.cornerRadius = 0.01;
       cell.bgView.layer.shadowColor = [UIColor whiteColor].CGColor;
       
       if (indexPath.row%2!=0) {
           cell.bgView.backgroundColor = [[UIColor colorWithHEX:mainBlackColor] colorWithAlphaComponent:0.5];
       }
       else {
           cell.bgView.backgroundColor = [UIColor whiteColor];
       }
       
       return cell;
}

@end
